<template>
	<view class="apps">
		<uv-subsection :list="tabs" :current="current" @change="change"></uv-subsection>
		<view class="flex fdc ptb10 plr20" v-if="list.length > 0">
			<view class="flex fdc  bgwhite mb20" v-for="(item,index) in list" :key="index">
				<view class="flex aic jcsa bdb1d bceee plr10 ptb20">
					<view class="flex f1 red f14 ">{{item.gift_code}}</view>
					<view class="flex f26">
						{{ formatTime(item.create_time) }}
					</view>
				</view>
				<view class="flex aic jcsa plr10 ptb20">
					<view class="flex f1 f26 ">
						<view v-if="item.status == 1">待核销</view>
						<view v-if="item.status == 2">已核销</view>
						<view v-if="item.status == 3">已失效</view>
					</view>
					<view class="flex f1 f22 plr10 ptb10" v-if="item.status == 2" style="color:#999;">
						核销时间:{{ formatTime(item.update_time) }}
					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<uv-empty icon="empty-page"></uv-empty>
		</view>
	</view>
</template>

<script>
	import { util } from '/common/util.js';
	import { timeFormat } from '@/uni_modules/uv-ui-tools/libs/function/index.js';
	let app;
	export default {
		data() {
			return {
				current:0,
				tabs:[
					{name:'全部',value:'0'},
					{name:'未核销',value:'1'},
					{name:"已核销",value:'2'},
					{name:'已失效',value:'3'},
				],
				list:[],
				page:1,
				more:true
			}
		},
		onLoad(){
			this.getList();
			app = this;
		},
		onReachBottom() {
			if(this.more){
				this.getList();
			}
		},
		methods: {
			formatTime(e){
				return timeFormat(e*1000,'yyyy-mm-dd hh:MM');
			},
			change(index){
				this.current = index;
				this.page = 1;
				this.more=true;
				this.getList();
			},
			getList(){
				const page = this.page;
				util.request({
					url:'/mpuser/qcodelist',
					data:{page:page,status:this.tabs[this.current].value}
				}).then((res)=>{
					if(res.code == 1){
						if(res.data.length < 10){
							app.more = false;
						}
						if(app.page == 1){
							app.list = res.data;
						}else{
							app.list.push(...res.data);
						}
						app.page= page + 1;
					}
				})
			}
		}
	}
</script>

<style>

</style>
